<!--
 * @Author: 刘十三
 * @Date: 2023-12-28 14:56:27
 * @LastEditors: 刘十三
 * @LastEditTime: 2024-02-03 16:36:33
 * @FilePath: \NM-dev-1.3.1\dev\pages\internal\linkage\todo\components\informationCheck.vue
 * @Description: 内蒙多员联动 - 信息录入审批（核查安排表单）
-->

<template>
  <view class="form-main">
    <u-form class="u-form-m" :model="checkForm" :error-type="['border-bottom', 'toast']" label-width="auto" label-position="top" ref="uForm">
      <u-form-item label="核查日期" prop="handleDate" :required="isEdit">
        <u-input placeholder="请选择" v-model="checkForm.handleDate" :disabled="true" @click="clickDatekHandle"></u-input>
      </u-form-item>
      <u-form-item label="核查人" prop="nextHandlePersonsName" :required="isEdit">
        <u-input placeholder="提交时选择" v-model="checkForm.nextHandlePersonsName" :disabled="true"></u-input>
      </u-form-item>
      <u-form-item label="检查情况" prop="checkMatchStatus" :required="isEdit">
        <u-radio-group v-model="checkForm.checkMatchStatus" :disabled="!isEdit">
          <u-radio v-for="(item, index) in list" :key="index" :name="item.value">
            {{ item.name }}
          </u-radio>
        </u-radio-group>
      </u-form-item>
      <u-form-item label="检查情况描述" prop="handleComment" :required="isEdit">
        <u-input placeholder="请输入" v-model="checkForm.handleComment" type="textarea" height="100" :auto-height="true" :disabled="!isEdit" maxlength="200" />
      </u-form-item>
      <u-form-item label="" prop="">
        <u-row style="width:100%">
          <u-col span="12" class="left-label" text-align="right">{{ checkForm.handlePersonsDeptName }}：{{ checkForm.handlePersonsName }}</u-col>
          <u-col span="12" class="right-label" text-align="right">{{ checkForm.createdAt }}</u-col>
        </u-row>
      </u-form-item>
      <u-form-item label="信息核查" prop="id" :border-bottom="false">
        <view style="margin-left:-5px">
          <view v-if="!isEdit && fileList.length == 0">
            <u-icon name="attach" color="#2979ff" size="28"></u-icon>
            <span style="font-size: 16px;color: #393B3D;">未上传</span>
          </view>
          <m-upload :deletable="isEdit" :disabled="!isEdit" :maxCount="10" width="150rpx" height="150rpx" :file-list="fileList" :multiple="true" index="doorwayUpload" :uploadParam="{ fiGroupCode: $FILE_GROUP_TYPE.l_diversification_attr, bizId: checkForm.id }" upApiUrl="uploadBase64ForApp" ref="filePicUpload" @on-list-change="handleUpdate" />
        </view>
      </u-form-item>
    </u-form>
    <!-- 日历 -->
    <u-picker mode="time" v-model="showTimeVisable" :params="params" :safe-area-inset-bottom="true" @confirm="changeDate"></u-picker>
  </view>
</template>

<script>
import mUpload from "@/components/m-upload.vue";
import { uuid } from "@/common/util.js";
import commonService from "@/service/common/common.service";
import moment from "moment";
export default {
  components: { mUpload },
  name: "informationPlan",
  props: {
    isEdit: {
      type: Boolean, // 是否可以编辑  false 不可以编辑
      default: false,
    },
    form: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      list: [
        {
          name: "核查不一致",
          value: "1",
        },
        {
          name: "核查一致",
          value: "0",
        },
      ],
      checkForm: {
        id: "",
        checkMatchStatus: "1", // 检查情况 (这里一开始就反了 ！！！！ 只能这样写了)
        handleDate: "", // 核查日期
        handleComment: "", // 核查意见
        nextHandlePersonsId: "", // 下一级审批人ID
        nextHandlePersonsName: "", //  下一级审批人NAME
        handlePersonsName: "", // 当前人
        createdAt: "", // 当前时间
        handlePersonsDeptName: "", //当前人的组织name
      },
      rules: {
        checkMatchStatus: [
          {
            required: true,
            message: "请选择检查情况",
            trigger: ["blur", "change"],
          },
        ],
        handleDate: [
          {
            required: true,
            message: "请选择核查日期",
            trigger: ["blur", "change"],
          },
        ],
        handleComment: [
          {
            required: true,
            message: "请输入检查情况描述，最多200个字",
            trigger: ["blur", "change"],
          },
        ],
      },
      showTimeVisable: false,
      params: {
        year: true,
        month: true,
        day: true,
        hour: false,
        minute: false,
        second: false,
      },
      fileList: [],
    };
  },
  methods: {
    handleUpdate(list) {
      if (list.length > 0) {
        this.fileList = [...list];
      } else {
        this.fileList = [];
      }
    },
    getFile(uuid) {
      commonService.goFiles(uuid, this.$FILE_GROUP_TYPE.l_diversification_attr).then((rs) => {
        if (rs.success) {
          if (rs.data.length > 0) {
            rs.data.forEach((item) => {
              this.fileList.push({ fileId: item.gfiId, gfiId: item.gfiId });
            });
          }
        } else {
          this.$u.toast(rs.msg);
        }
      });
    },
    clickDatekHandle() {
      if (this.isEdit) {
        this.showTimeVisable = true;
      }
    },
    changeDate(value) {
      this.checkForm.handleDate = value.year + "-" + value.month + "-" + value.day;
      this.showTimeVisable = false;
    },
    getCurDate() {
      return moment().format("YYYY-MM-DD");
    },
    getCurTime() {
      return moment().format("YYYY-MM-DD hh:MM:ss");
    },
  },
  mounted() {
    this.$refs.uForm.setRules(this.rules);
    if (this.isEdit) {
      this.checkForm.id = uuid();
      this.checkForm.handleDate = this.getCurDate();
      this.checkForm.handlePersonsDeptName = this.curUser.deptName;
      this.checkForm.handlePersonsName = this.curUser.user.personName;
      this.checkForm.createdAt = this.getCurDate();
    } else {
      this.checkForm = this.form;
      this.getFile(this.checkForm.id);
    }
  },
};
</script>

<style lang="scss" scoped>
.u-form-m {
  padding: 0px 5px;
}
</style>
